package com.wetao.lib_common.greendao.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.wetao.lib_common.greendao.model.PagePictureGrid;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "PAGE_PICTURE_GRID".
*/
public class PagePictureGridDao extends AbstractDao<PagePictureGrid, Long> {

    public static final String TABLENAME = "PAGE_PICTURE_GRID";

    /**
     * Properties of entity PagePictureGrid.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property QuestionId = new Property(1, Integer.class, "questionId", false, "QUESTION_ID");
        public final static Property QuestionNo = new Property(2, Integer.class, "questionNo", false, "QUESTION_NO");
        public final static Property StartX = new Property(3, Float.class, "startX", false, "START_X");
        public final static Property StartY = new Property(4, Float.class, "startY", false, "START_Y");
        public final static Property EndX = new Property(5, Float.class, "endX", false, "END_X");
        public final static Property EndY = new Property(6, Float.class, "endY", false, "END_Y");
        public final static Property QuestionType = new Property(7, Integer.class, "questionType", false, "QUESTION_TYPE");
        public final static Property PagePictureId = new Property(8, Long.class, "pagePictureId", false, "PAGE_PICTURE_ID");
    }

    private Query<PagePictureGrid> pagePicture_GridListQuery;

    public PagePictureGridDao(DaoConfig config) {
        super(config);
    }
    
    public PagePictureGridDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"PAGE_PICTURE_GRID\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"QUESTION_ID\" INTEGER NOT NULL ," + // 1: questionId
                "\"QUESTION_NO\" INTEGER," + // 2: questionNo
                "\"START_X\" REAL," + // 3: startX
                "\"START_Y\" REAL," + // 4: startY
                "\"END_X\" REAL," + // 5: endX
                "\"END_Y\" REAL," + // 6: endY
                "\"QUESTION_TYPE\" INTEGER," + // 7: questionType
                "\"PAGE_PICTURE_ID\" INTEGER NOT NULL );"); // 8: pagePictureId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"PAGE_PICTURE_GRID\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, PagePictureGrid entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getQuestionId());
 
        Integer questionNo = entity.getQuestionNo();
        if (questionNo != null) {
            stmt.bindLong(3, questionNo);
        }
 
        Float startX = entity.getStartX();
        if (startX != null) {
            stmt.bindDouble(4, startX);
        }
 
        Float startY = entity.getStartY();
        if (startY != null) {
            stmt.bindDouble(5, startY);
        }
 
        Float endX = entity.getEndX();
        if (endX != null) {
            stmt.bindDouble(6, endX);
        }
 
        Float endY = entity.getEndY();
        if (endY != null) {
            stmt.bindDouble(7, endY);
        }
 
        Integer questionType = entity.getQuestionType();
        if (questionType != null) {
            stmt.bindLong(8, questionType);
        }
        stmt.bindLong(9, entity.getPagePictureId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, PagePictureGrid entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindLong(2, entity.getQuestionId());
 
        Integer questionNo = entity.getQuestionNo();
        if (questionNo != null) {
            stmt.bindLong(3, questionNo);
        }
 
        Float startX = entity.getStartX();
        if (startX != null) {
            stmt.bindDouble(4, startX);
        }
 
        Float startY = entity.getStartY();
        if (startY != null) {
            stmt.bindDouble(5, startY);
        }
 
        Float endX = entity.getEndX();
        if (endX != null) {
            stmt.bindDouble(6, endX);
        }
 
        Float endY = entity.getEndY();
        if (endY != null) {
            stmt.bindDouble(7, endY);
        }
 
        Integer questionType = entity.getQuestionType();
        if (questionType != null) {
            stmt.bindLong(8, questionType);
        }
        stmt.bindLong(9, entity.getPagePictureId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public PagePictureGrid readEntity(Cursor cursor, int offset) {
        PagePictureGrid entity = new PagePictureGrid( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getInt(offset + 1), // questionId
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // questionNo
            cursor.isNull(offset + 3) ? null : cursor.getFloat(offset + 3), // startX
            cursor.isNull(offset + 4) ? null : cursor.getFloat(offset + 4), // startY
            cursor.isNull(offset + 5) ? null : cursor.getFloat(offset + 5), // endX
            cursor.isNull(offset + 6) ? null : cursor.getFloat(offset + 6), // endY
            cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7), // questionType
            cursor.getLong(offset + 8) // pagePictureId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, PagePictureGrid entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setQuestionId(cursor.getInt(offset + 1));
        entity.setQuestionNo(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setStartX(cursor.isNull(offset + 3) ? null : cursor.getFloat(offset + 3));
        entity.setStartY(cursor.isNull(offset + 4) ? null : cursor.getFloat(offset + 4));
        entity.setEndX(cursor.isNull(offset + 5) ? null : cursor.getFloat(offset + 5));
        entity.setEndY(cursor.isNull(offset + 6) ? null : cursor.getFloat(offset + 6));
        entity.setQuestionType(cursor.isNull(offset + 7) ? null : cursor.getInt(offset + 7));
        entity.setPagePictureId(cursor.getLong(offset + 8));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(PagePictureGrid entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(PagePictureGrid entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(PagePictureGrid entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "gridList" to-many relationship of PagePicture. */
    public List<PagePictureGrid> _queryPagePicture_GridList(Long pagePictureId) {
        synchronized (this) {
            if (pagePicture_GridListQuery == null) {
                QueryBuilder<PagePictureGrid> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.PagePictureId.eq(null));
                pagePicture_GridListQuery = queryBuilder.build();
            }
        }
        Query<PagePictureGrid> query = pagePicture_GridListQuery.forCurrentThread();
        query.setParameter(0, pagePictureId);
        return query.list();
    }

}
